<template>
  <BasicDrawer v-bind="$attrs" @register="registerDrawer" showFooter :title="getTitle" width="70%" @ok="handleSubmit">
    <vxe-grid ref="tableRef" v-bind="gridOptions" :style="{height: (contentHeight*0.9)+'px'}">
      <template #toolbar_buttons>
      </template>


    </vxe-grid>

  </BasicDrawer>
</template>
<script lang="ts" setup>
import {ref, computed, unref, reactive} from 'vue';
import { BasicForm, useForm, ApiSelect } from '@/components/Form';
import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
import {formSchema,  vxeTableColumns2} from './role.data';
import util from "@/utils/util";

import { useModal } from "@/components/Modal";
import { useMessage } from "@/hooks/web/useMessage";
import { useUserStore } from "@/store/modules/user";
import {BasicTableProps} from "@/components/VxeTable";

import {Button, Descriptions, DescriptionsItem} from "ant-design-vue";
const userStore = useUserStore();

const [registerModal, { openModal }] = useModal();

const emit = defineEmits(['success', 'register']);
const isUpdate = ref(true);
const dataList = ref({});
const { createMessage } = useMessage();

const id = ref("");
const contentHeight = ref(window.innerHeight);



const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
  //打开弹层后的回调
  setDrawerProps({ confirmLoading: false });
  // 需要在setFieldsValue之前先填充treeData，否则Tree组件可能会报key not exist警告
  // if (unref(treeData).length === 0) {
  //   treeData.value = (await getMenuList()) as any as TreeItem[];
  // }
  isUpdate.value = !!data?.isUpdate;
  id.value = "";
  dataList.value=data;
  tableRef.value.reloadData(data.list);

});

const gridOptions = reactive<BasicTableProps>({
  // keepSource: true,
  editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
  border: true,
  showOverflow: true,
  size: 'mini',
  height: 'auto', // 'auto'
  columns: vxeTableColumns2,
  mergeCells: [
    { row: 0, col: 0, rowspan: 7, colspan: 0 },
  ],
  filterConfig: {
    remote: true,
  },
  expandConfig: {
    padding: true
  },
  showFooter: true,
  footerData: [
    { userName: '合计' }
  ],
  toolbarConfig: {
    slots: {
      buttons: 'toolbar_buttons',
    },
    refresh: true,
  },
  formConfig: {
    // enabled: true,
  },
  pagerConfig: {
    // pageSize: 20,
  },
  exportConfig:{},
  proxyConfig: {
    enabled: false,
  },
});

const tableRef = ref();

const getTitle = computed(() => (!unref(isUpdate) ? '明细' : '明细'));





</script>
